package com.pacific.sign.biz.service.impl;

import com.pacific.common.exception.BizException;
import com.pacific.sign.dal.dao.pac.custom.RoleMenuCustom;
import com.pacific.sign.model.po.pac.mbg.PacHcRoleMenu;
import com.pacific.sign.model.po.pac.response.PacHcRoleMenuResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 角色菜单映射
 */
@Service
public class RoleMenuService {

    @Autowired
    private RoleMenuCustom roleMenuCustom;

    /**
     * 查询
     */
    public PacHcRoleMenuResponse query(PacHcRoleMenu model){
        PacHcRoleMenuResponse resp = new PacHcRoleMenuResponse();
        List<PacHcRoleMenu> list = roleMenuCustom.selectByConditions(model);

        resp.setList(list);
        return resp;
    }

    public int insert(PacHcRoleMenu obj){
        int i = roleMenuCustom.insert(obj);
        if(i <1){
            throw new BizException("新增失败");
        }
        return i;
    }

    public int update(PacHcRoleMenu obj){
        int i = roleMenuCustom.updateById(obj);
        if(i <1){
            throw new BizException("更新失败");
        }
        return i;
    }

    public int delete(PacHcRoleMenu obj){
        if(obj == null || obj.getId() == null){
            throw new BizException("主键为空");
        }
        int i = roleMenuCustom.deleteById(String.valueOf(obj.getId()));
        if(i <1){
            throw new BizException("删除失败");
        }
        return i;
    }

    public PacHcRoleMenu selectById(Integer id){
        if(id == null){
            throw new BizException("主键为空");
        }
        return roleMenuCustom.selectById(String.valueOf(id));
    }
}
